<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\logic;

use app\common\model\UserAccount;
use app\common\model\ApplicationClass;
use think\Db;

/**
 * Bank逻辑
 */
class Application extends LogicBase
{

    /**
     * 获取Application列表
     */
    public function getApplicationList($where = [], $field = 'a.*', $order = 'sort desc')
    {

        $this->modelApplication->alias('a');



        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];

        $count=$this->modelApplication->where($where)->count();
        $this->modelApplication->alias('a');
        return ['list'=>$this->modelApplication->getList($where, $field, $order),'count'=>$count] ;
    }

    public function getApplicationClassList($where = [], $field = 'a.*', $order = 'sort desc'){
        $this->modelApplicationClass->alias('a');



        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];

        $count=$this->modelApplicationClass->where($where)->count();
        $this->modelApplicationClass->alias('a');
        return ['list'=>$this->modelApplicationClass->getList($where, $field, $order),'count'=>$count] ;
    }

    /**
     * 获取Application列表搜索条件
     */
    public function getWhere($data = [])
    {

        $where = [];

        !empty($data['search_data']) && $where['a.name'] = ['like', '%'.$data['search_data'].'%'];

        return $where;
    }

    /**
     * Application信息编辑
     */
    public function ApplicationEdit($data = [])
    {

        $validate_result = $this->validateApplication->scene('edit')->check($data);

        if (!$validate_result) {

            return [RESULT_ERROR, $this->validateApplication->getError()];
        }

        $url = url('ApplicationList');


        $result = $this->modelApplication->setInfo($data);


        $handle_text = empty($data['id']) ? '新增' : '编辑';

        $result && action_log($handle_text, 'Bank' . $handle_text );

        return $result ? [RESULT_SUCCESS, 'Application操作成功', $url] : [RESULT_ERROR, $this->modelApplication->getError()];
    }

    /**
     * 获取Application信息
     */
    public function getApplicationInfo($where = [], $field = 'a.*')
    {

        $this->modelApplication->alias('a');


        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];

        return $this->modelApplication->getInfo($where, $field);
    }




}
